<?php

/**
 * This is the model class for table "mission_assignment".
 *
 * The followings are the available columns in table 'mission_assignment':
 * @property integer $id
 * @property integer $total_months_rendered
 * @property string $assignment_length
 * @property string $assignment_start_date
 * @property string $assignment_end_date
 * @property string $assignment_status
 * @property integer $mission_area_id
 * @property integer $volunteer_id
 *
 * The followings are the available model relations:
 * @property MissionArea $missionArea
 * @property Volunteer $volunteer
 */
class MissionAssignment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MissionAssignment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mission_assignment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('total_months_rendered, assignment_length, assignment_start_date, assignment_end_date, assignment_status, mission_area_id, volunteer_id', 'required'),
			array('total_months_rendered, mission_area_id, volunteer_id', 'numerical', 'integerOnly'=>true),
			array('assignment_length, assignment_status', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, total_months_rendered, assignment_length, assignment_start_date, assignment_end_date, assignment_status, mission_area_id, volunteer_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'missionArea' => array(self::BELONGS_TO, 'MissionArea', 'mission_area_id'),
			'volunteer' => array(self::BELONGS_TO, 'Volunteer', 'volunteer_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'total_months_rendered' => 'Months Rendered',
			'assignment_length' => 'Length',
			'assignment_start_date' => 'Start Date',
			'assignment_end_date' => 'End Date',
			'assignment_status' => 'Status',
			'mission_area_id' => 'Mission Area',
			'volunteer_id' => 'Volunteer',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('total_months_rendered',$this->total_months_rendered);
		$criteria->compare('assignment_length',$this->assignment_length,true);
		$criteria->compare('assignment_start_date',$this->assignment_start_date,true);
		$criteria->compare('assignment_end_date',$this->assignment_end_date,true);
		$criteria->compare('assignment_status',$this->assignment_status,true);
		$criteria->compare('mission_area_id',$this->mission_area_id);
		$criteria->compare('volunteer_id',$this->volunteer_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	 public function getVolunteerName()
	{
		return $this->volunteer->volunteerName;
	}

	public function getMissionName()
	{
		return $this->missionArea->missionName;
	}

	public function getAssignment()
	{
		return $this->missionArea->missionName.' - '.$this->volunteer->volunteerName ;
	}

	public function getStatus()
	{
		return array('ongoing'=>'ongoing', 'finished'=>'finished');
	}
}